﻿using System;
using System.Collections.Generic;
using System.Linq;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Transformable_Engine_v2.Engine.GameObjects.Containers
{
    public abstract class BaseListContainer : Container
    {
        public new List<BaseListContainerElement> Children { get { return base.Children.Select(x => x as BaseListContainerElement).ToList(); } } 

        protected BaseListContainerElement GetLatestChild()
        {
            return Children[Children.Count - 1];
        }

        public void AddListChildren(params BaseListContainerElement[] children)
        {
            foreach (BaseListContainerElement child in children)
            {
                if (Children.Count > 0)
                {
                    child.Position = GetNextElementPosition(child.Position);
                }

                base.AddChild(child);
            }
        }

        protected abstract TE_Vector2 GetNextElementPosition(TE_Vector2 childPosition);

        public override void AddChildren(params Container[] children)
        {
            throw new Exception("Do not use this. Use AddListChildren instead");
        }
    }
}